package com.henrik.bak.esportcalendar.dbutils;

import java.sql.SQLException;
import java.util.List;

import android.content.Context;

import com.henrik.bak.esportcalendar.model.Event;
import com.j256.ormlite.dao.Dao;

public class EventsRepository {
	 
    private DatabaseHelper db;
    Dao<Event, Integer> eventsDao;
 
    public EventsRepository(Context ctx)
    {
        try {
            DatabaseManager dbManager = new DatabaseManager();
            db = dbManager.getHelper(ctx);
            eventsDao = db.getEventsDao();
        } catch (SQLException e) {
            // TODO: Exception Handling
            e.printStackTrace();
        }
 
    }
 
    public int create(Event event)
    {
        try {
            return eventsDao.create(event);
        } catch (SQLException e) {
            // TODO: Exception Handling
            e.printStackTrace();
        }
        return 0;
    }
    public int update(Event event)
    {
        try {
            return eventsDao.update(event);
        } catch (SQLException e) {
            // TODO: Exception Handling
            e.printStackTrace();
        }
        return 0;
    }
    public int delete(Event event)
    {
        try {
            return eventsDao.delete(event);
        } catch (SQLException e) {
            // TODO: Exception Handling
            e.printStackTrace();
        }
        return 0;
    }
 
    public List<Event> getAll()
    {
        try {
            return eventsDao.queryForAll();
        } catch (SQLException e) {
            // TODO: Exception Handling
            e.printStackTrace();
        }
        return null;
    }
}
